package sax.utils;

import java.io.File;
import java.util.HashMap;
import java.util.Set;

import sax.representation.SAX;

/**
 * Class that initialize the process of creation of SAX representation.
 * 
 * @author Krzysztof Figaj
 *
 */
public class SAXBuilder {

	private HashMap<String, SAX> saxRepresentations;
	
	public static String test1 = "C:/Documents and Settings/Krzysztof/Pulpit/Studia/Semestr9/pdm-1/4/original/apple-1.gif";
	
	public static String test2 = "test_image/apple-1.gif";
	public static String test3 = "test_image/temp.bmp";
	public static String test4 = "test_image/temp2.bmp";
	
	public static String test5 = "test_image_1";
	
	public static void main(String args[]){
		String names[] = new String[]{test5};
		SAXBuilder saxBuilder = new SAXBuilder();
		saxBuilder.createSAXFromFiles(names);
		saxBuilder.displaySAX();
	}
	
	public SAXBuilder() {
		saxRepresentations = new HashMap<String, SAX>();
	}
	
	public void createSAXFromFiles(String imageNames[]){
		
		for(String imageName: imageNames){
			try{
				File file = new File(imageName);
				
				if(file.isDirectory()){
					String[] childrenFiles = file.list();
					for(String s : childrenFiles){
						System.out.println("Procesing file:"+imageName+"/"+s);
						saxRepresentations.put(imageName+"/"+s,
								SAXCreator.create(imageName+"/"+s));
					}	
				}else{
					System.out.println("Procesing file:"+imageName);
					saxRepresentations.put(imageName,
							SAXCreator.create(imageName));
				}		
			} catch(Exception e){
				System.out.println(e.getStackTrace());
			}
		}
		
	}
	
	public void displaySAX(){
		Set<String> keySAX = saxRepresentations.keySet();
		for(String s : keySAX){
			System.out.println("SAX for: "+s+" "+
					saxRepresentations.get(s).getSax());
		}
	}
	
	public HashMap<String, SAX> getSAXRepresentations(){
		return saxRepresentations;
	}
	
	
}
